﻿

Public Class frmSupplyManagement
    Dim Mysql As New ClsSQLhelper
    Dim Strsql As String


    Function Load_Data(Optional ByVal siteid As Integer = 0, Optional ByVal Str_Search As String = "") As Boolean
        Try

            Dim DS As New DataSet

            Load_Data = False
         

            Dim ColCompanyid As New DataGridViewTextBoxColumn
            Dim ColCompanycode As New DataGridViewTextBoxColumn
            Dim ColCompanyName As New DataGridViewTextBoxColumn
            Dim ColCompanyType As New DataGridViewTextBoxColumn
            Dim ColContactName As New DataGridViewTextBoxColumn
            Dim Coltaxid As New DataGridViewTextBoxColumn
            Dim Coltel As New DataGridViewTextBoxColumn
            Dim Colfax As New DataGridViewTextBoxColumn
            Dim Colnote As New DataGridViewTextBoxColumn
            Dim active As New DataGridViewCheckBoxColumn

            With ColCompanyid
                .HeaderText = "ID"
                .Width = "50"
                .DataPropertyName = "companyid"
            End With
            With ColCompanycode
                .HeaderText = "รหัสบริษัท"
                .Width = "100"
                .DataPropertyName = "companycode"
            End With
            With ColCompanyName
                .HeaderText = "ชื่อบริษัท"
                .Width = "150"
                .DataPropertyName = "companyname"
            End With
            With ColCompanyType
                .HeaderText = "ประเภท"
                .Width = "180"
                .DataPropertyName = "vendor_type_name"
            End With
            With ColContactName
                .HeaderText = "ชื่อผุ้ติดต่อ"
                .Width = "100"
                .DataPropertyName = "contactname"
            End With
            With Coltaxid
                .HeaderText = "TAX ID"
                .Width = "100"
                .DataPropertyName = "taxid"
            End With
            With Coltel
                .HeaderText = "เบอร์โทรศัพท์"
                .Width = "100"
                .DataPropertyName = "tel"
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            End With
            With Colfax
                .HeaderText = "แฟกซ์"
                .Width = "100"
                .DataPropertyName = "fax"
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            End With
            With Colnote
                .HeaderText = "หมายเหตุ"
                .Width = "150"
                .DataPropertyName = "note"
            End With
            With active
                .HeaderText = "เปิดใช้งาน"
                .Width = "100"
                .DataPropertyName = "active"
            End With





            '  Pn_Framework.Set_GridSetting(GridCompanyList, DS)

            With GridCompanyList
                .Columns.Clear()
                .ReadOnly = True
                Strsql = "select companyid,companycode,companyname,vendorcompanytype.vendor_type_name,contactname,taxid,tel,fax,note,active from vendorcompany left join vendorcompanytype on companytype = vendor_type_id  order by active desc,companyName" 'where siteid = " & siteid

                DS = Mysql.GetMYSQLDataset(Strsql, "DSvendorcompany", "vendorcompany")
                .AutoGenerateColumns = False
                .DataSource = DS.Tables("vendorcompany")
                .Columns.Add(ColCompanyid)
                .Columns.Add(ColCompanycode)
                .Columns.Add(ColCompanyName)
                .Columns.Add(ColCompanyType)
                .Columns.Add(ColContactName)
                .Columns.Add(Coltaxid)
                .Columns.Add(Coltel)
                .Columns.Add(Colfax)
                .Columns.Add(Colnote)
                .Columns.Add(active)
            End With

            Load_Data = True
        Catch ex As Exception

            MsgBox(ex.Message())
        End Try

    End Function
    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Close()
    End Sub

    Private Sub frmSupplyManagement_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Load_Data()

    End Sub
    Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNew.Click
        frmSupplyInfo.MdiParent = frmmain
        frmSupplyInfo.New_Entry_State = True
        frmSupplyInfo.Show()
    End Sub

    Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
        frmSupplyInfo.MdiParent = frmmain
        frmSupplyInfo.New_Entry_State = False
        frmSupplyInfo.TxtID.Text = Me.GridCompanyList.Rows(GridCompanyList.CurrentCell.RowIndex).Cells(0).Value
        frmSupplyInfo.Show()
    End Sub

    Private Sub GridCompanyList_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridCompanyList.CellDoubleClick
        frmSupplyInfo.MdiParent = frmmain
        frmSupplyInfo.New_Entry_State = False
        frmSupplyInfo.TxtID.Text = Me.GridCompanyList.Rows(GridCompanyList.CurrentCell.RowIndex).Cells(0).Value
        frmSupplyInfo.Show()
    End Sub

    Private Sub GridCompanyList_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridCompanyList.CellContentClick

    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub
End Class